#====# Appendix E: Estimation window goodness-of-fit #====#

# Load libraries and set defaults ----
library(modelsummary)
library(tinytable)
library(bizdays)
library(tidyverse)
library(tidylog, warn.conflicts = FALSE)

# prepare business calendar:
business_calendar <- create.calendar('biz_calendar', weekdays = c('saturday','sunday'))

# Import data ----
stocks <- read_rds("data_out/stocks_analysis.rds") # main analysis dataset

# Table E.1: Descriptive statistics of relevant variables ----
stocks %>%
  filter(date >= offset(event, -5, business_calendar) &
           date <= offset(event, +5, business_calendar)) %>%
  mutate(cshoq = cshoq/10^9) %>%
  select(cshoq, prccd, obs_chg, abn_chg,
         car) %>%
  rename("Closing price (\\$)" = "prccd",
         "Outstanding shares (B)" = "cshoq",
         "\\textsc{returns} (\\%)" = "obs_chg",
         "\\textsc{ar} (\\%)" = "abn_chg",
         "\\textsc{car} (\\%)" = "car") %>%
  datasummary(data = .,
              formula = All(.) ~ N + Mean + SD + Min + P25 + Median + P75 + Max,
              fmt = 3,
              title = "Descriptive statistics of relevant variables \\label{tab:stats}",
              escape = FALSE) %>%
  theme_tt("placement", latex_float = "!htbp") %>%
  theme_tt("resize", width = .9) %>%
  save_tt("tables/table_E1.html", overwrite = TRUE)

#====# The End #====#